using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SimpleGame.ScreenManagement;
using SimpleGame.ScreenManagement.Screens;
using SimpleGame.Utils;
using SimpleGame.Font;

namespace SimpleGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game : Microsoft.Xna.Framework.Game
    {
        #region XNA Fields

        private GraphicsDeviceManager graphics;
        private ScreenManager screenManager;

        #endregion

        #region Constructor

        public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            // Set resolution
            // TODO needs to be updated later to have the right resolution and if possible ingame changeable resolutions
            graphics.PreferredBackBufferWidth = 1000;
            graphics.PreferredBackBufferHeight = 650;
            // Turn vsync on. It's on by default, just to be save =)
            graphics.SynchronizeWithVerticalRetrace = true;

            // Set default root directory for easier access
            Content.RootDirectory = "Content";

            // Add the input manager as a game component. It will be updated automatically.
            Components.Add(new InputHandler(this));

            // Create the screen manager component and add it,
            // so it can be drawn and updated automatically
            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            // Add the fps counter and display as a drawable game component. It will be updated automatically.
            Components.Add(new FrameRateCounter(this));
        }

        #endregion

        #region XNA Methods

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // create and add Main Menu Screen to the ScreenManger
            //MainMenuScreen mainMenuScreen = new MainMenuScreen();
            //screenManager.AddScreen(mainMenuScreen);

            // for testing purposes add the gameplay screen right away
            screenManager.AddScreen(new GameplayScreen());

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // create the default font and add it to the FontManager. DO NOT CHANGE. this is needed for the FontManager to work.
            SpriteFont spriteFont = Content.Load<SpriteFont>(@"font/default");
            SimpleFont simpleFont = new SimpleFont(spriteFont, "default");
            FontManager.Instance.AddFont(simpleFont);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        #endregion
    }
}
